/*
* 练习
* */
const http = require('http')

const app = http.createServer((req, res) => {

    const method = req.method
    console.log('请求方法：',method)
    const url = new URL(req.url, 'http://127.0.0.1:3000/')
    // console.log(url)

    // 获取url请求路径
    const pathname = url.pathname
    console.log('请求路径：', pathname)

    // 设置响应头，解决乱码
    res.setHeader("Content-type", "text/html;charset=utf-8")
    if (method === 'GET' && pathname === '/login') {
        res.end('登录')
    } else if (method === 'GET' && pathname === '/reg') {
        res.end('注册')
    } else {
        res.end('Not Found')
    }

    // res.end('练习')
})

app.listen(3000, () => {
    console.log('服务已启动')
})